﻿using Engine;
using Game;
namespace Mekiasm
{
    public class ElectrolyzerWidget : BaseEnergyWidget
    {
        public ComponentElectrolyzer Component;
        ComponentEnergyMachine.Slot CraftSlot1;
        ComponentEnergyMachine.Slot ResultSlot1;
        ComponentEnergyMachine.Slot ResultSlot2;
        FluidBaseProgress FluidCraft;
        FluidBaseProgress FluidResult1;
        FluidBaseProgress FluidResult2;

        public ElectrolyzerWidget(ComponentElectrolyzer c, ComponentMiner m) : base(m)
        {
            Component = c;
            CraftSlot1 = Component.Slots[0];
            ResultSlot1 = Component.Slots[1];
            ResultSlot2 = Component.Slots[2];
            MekCraftingRecipe.FindCraftDevice(typeof(MekElectrolyzer)).GenerateRecipeWidget(CanvasMain, c,m, ref Tick);
            FluidCraft = CanvasMain.Children.Find<FluidBaseProgress>("c1");
            FluidResult1 = CanvasMain.Children.Find<FluidBaseProgress>("r1");
            FluidResult2 = CanvasMain.Children.Find<FluidBaseProgress>("r2");
            setTitle("电解分离器");
        }
        public override void Update()
        {
            Tick?.Invoke();
            FluidCraft.SetProgress((float)CraftSlot1.FuelAmount / CraftSlot1.FuelCapacity);
            FluidResult1.SetProgress((float)ResultSlot1.FuelAmount / ResultSlot1.FuelCapacity);
            FluidResult2.SetProgress((float)ResultSlot2.FuelAmount / ResultSlot2.FuelCapacity);
            SetLeftBottomMoreInfo($"能量消耗: {ILibrary.FormatPower(Component.OutputPowerLimit)}\n能量储存: {ILibrary.FormatPower(Component.Power)}\n最大储能:{ILibrary.FormatPower(Component.MaxPower)}");
            SetPowerProgress((float)Component.Power / Component.MaxPower);
        }
    }
}
